package net.gooduo.spring_boot_template.controller.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import net.gooduo.spring_boot_template.http.HttpResult;
import net.gooduo.spring_boot_template.http.request.admin.AdminLoginRequest;
import net.gooduo.spring_boot_template.service.AuthService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/admin/auth")
public class AuthController {
    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("login")
    public HttpResult login(@Valid @RequestBody AdminLoginRequest data) {
        return HttpResult.data(authService.login(data.getUsername(), data.getPassword()));
    }

    @GetMapping("info")
    @SaCheckLogin
    public HttpResult info() {
        return HttpResult.data(authService.info());
    }
}
